﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv-se" lang="sv-se">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link rel="stylesheet" href="stylesheet.css" type="text/css"/>
    <title>Lägg till regissör - status</title>
</head>
<body>
	<?php 
		require("DbSettings.php");
		$conn = mysql_connect($server, $username, $password);
		mysql_select_db($db, $conn);
		
		$firstNameParam = htmlspecialchars(mysql_real_escape_string(trim($_POST["firstName"])));
		$lastNameParam = htmlspecialchars(mysql_real_escape_string(trim($_POST["lastName"])));
				
		if ($firstNameParam == "" || $lastNameParam == "") {
			echo '<div class="errorMsg">Fel! Förnamn och efternamn måste anges!</div>';
			
			echo '<a href="addDirector.htm">Nytt försök</a><br/><a href="index.htm">Startsidan</a>';			
		}
		else {
			$sql = 'SELECT FirstName FROM director WHERE FirstName=\''.$firstNameParam.'\' AND LastName=\''.$lastNameParam.'\'';
			
			$query = mysql_query($sql);
			
			$rows = mysql_num_rows($query);
		
			if ($rows == 0){
							
				$sql = 'INSERT INTO director (FirstName, LastName) VALUES (\''.$firstNameParam.'\', \''.$lastNameParam.'\')';
			
				mysql_query($sql);
			
				mysql_close($conn);
			
				echo '<div class="infoMsg">Det gick bra! Tack!</div>';

				echo '<a href="addDirector.htm">Lägg till ny regissör</a><br/><a href="index.htm">Startsidan</a>';	
			}
			else {
				echo '<div class="errorMsg">Regissören finns redan!</div>';
				
				echo '<a href="addDirector.htm">Lägg till ny regissör</a><br/><a href="index.htm">Startsidan</a>';
			}
			
		}
	?>
</body>
</html>
